import CommonFunction from "../utils/CommonFunction";

const { ccclass, property } = cc._decorator;

@ccclass
export default class DebugPanel extends cc.Component {
    static Instance: DebugPanel;

    @property(cc.Node)
    Button_close: cc.Node = null;
    @property(cc.Node)
    main: cc.Node = null;
    @property(cc.Node)
    parent: cc.Node = null;

    list: any[] = new Array();

    onLoad() {
        DebugPanel.Instance = this;
    }

    start() {
        this.Button_close.on(
            "click",
            () => {
                this.ShowOff();
            },
            this
        );

        this.AddButtons();

        CommonFunction.SetAllChildrenAtive(this.parent, false);
        for (let i = 0; i <= this.list.length - 1; i++) {
            let obj = this.list[i];

            let child = CommonFunction.GetFreeChild(this.parent);
            child.active = true;

            let label = child.getComponentInChildren(cc.Label);
            label.string = obj.title;

            child.on(
                "click",
                () => {
                    obj.callback();
                    // this.ShowOff();
                },
                this
            );
        }
    }

    AddButtons() {
        this.list.push({
            title: "生成字索引成语表",
            callback: () => {
                // GameManager.GetList_word();
            },
        });

        this.list.push({
            title: "生成目标成语",
            callback: () => {
                console.log(`---------------------`);
            },
        });
    }

    ShowOn() {
        // this.node.active = true;
        this.main.active = true;
    }

    ShowOff() {
        // this.node.active = false;
        this.main.active = false;
    }
}
